package in.muton.edushare.poll.components;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.poll.pages.PollAnswer;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;

import com.edushare.common.dao.UserPollDAO;
import com.edushare.common.vo.Poll;

public class PreviewLink extends Link<Void> {
	private static final long serialVersionUID = 5686593441998420344L;
	private IModel<Poll> pollModel;

	public PreviewLink(String id, IModel<Poll> model) {
		super(id);
		this.pollModel = model;
	}

	@Override
	public void onClick() {
		PageParameters p = new PageParameters();
		p.add("0", Integer.toString(pollModel.getObject().getPollId()));
		setResponsePage(PollAnswer.class, p);
	}

	@Override
	public boolean isVisible() {
		UserPollDAO upDAO = new UserPollDAO(EduShareSession.get()
				.getSessionORMInterface());
		if (upDAO.getPollObservers(pollModel.getObject()).contains(
				EduShareSession.get().getLoggedInUser()))
			return true;
		return false;
	}
}
